package com.yungu.swift.api.route.v1.driver;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.google.common.collect.Lists;
import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.api.base.Constants;
import com.yungu.swift.api.utils.FileUploadUtil;
import com.yungu.swift.api.utils.RandomUtil;
import com.yungu.swift.assets.driver.model.dto.DriverCashDto;
import com.yungu.swift.assets.driver.model.dto.DriverDto;
import com.yungu.swift.assets.driver.model.param.DriverRemindParam;
import com.yungu.swift.assets.driver.model.vo.DriverEvaluationVo;
import com.yungu.swift.assets.driver.model.vo.DriverSignLogVo;
import com.yungu.swift.assets.driver.model.vo.DriverVo;
import com.yungu.swift.assets.driver.service.DriverCashService;
import com.yungu.swift.assets.driver.service.DriverService;
import com.yungu.swift.assets.driver.service.DriverSignLogService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.api.ApiPageParam;
import com.yungu.swift.common.model.dto.CommonEvaluateCountDto;
import com.yungu.swift.common.model.dto.CommonFeedbackDto;
import com.yungu.swift.common.model.dto.CommonIdentifyDto;
import com.yungu.swift.common.model.dto.CommonStarCountDto;
import com.yungu.swift.common.service.CommonEvaluateCountService;
import com.yungu.swift.common.service.CommonFeedbackService;
import com.yungu.swift.common.service.CommonSmsService;
import com.yungu.swift.common.service.CommonStarCountService;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.constants.FinanceConstant;
import com.yungu.swift.constants.MagicConstant;
import com.yungu.swift.order.model.dto.OrderEvaluateDto;
import com.yungu.swift.order.service.OrderEvaluateService;
import com.yungu.swift.order.service.OrderFareService;
import com.yungu.swift.system.finance.service.FinanceInviteRewardService;
import com.yungu.swift.system.finance.service.FinanceOrderService;
import com.yungu.swift.system.marketing.model.dto.MarketingGiftDto;
import com.yungu.swift.system.marketing.model.dto.MarketingShareDto;
import com.yungu.swift.system.marketing.model.vo.MarketingShareVo;
import com.yungu.swift.system.marketing.service.MarketingCouponService;
import com.yungu.swift.system.marketing.service.MarketingGiftService;
import com.yungu.swift.system.marketing.service.MarketingInviteLogService;
import com.yungu.swift.system.marketing.service.MarketingShareService;
import com.yungu.swift.utils.MapUtils;
import com.yungu.swift.utils.ParamUtil;
import com.yungu.swift.utils.StringUtils;
import com.yungu.swift.utils.ValidateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;

import static com.yungu.swift.api.config.NacosListener.SYS_CONFIG;

/**
 * Created by Administrator on 2016/12/12.
 */
@Controller
@RequestMapping(value = "/api/v1/driver")
@Api(value = "【司机】【用户信息】司机信息接口", tags = "司机信息相关操作")
public class DriUserInfoApi extends BaseApi {
    @Reference
    private DriverService driverService;
    @Reference
    private DriverSignLogService driverSignLogService;
    @Reference
    private CommonSmsService commonSmsService;
    @Reference
    private OrderEvaluateService orderEvaluateService;
    @Reference
    private CommonFeedbackService commonFeedbackService;
    @Reference
    private DriverCashService driverCashService;
    @Reference
    private CommonStarCountService commonStarCountService;
    @Reference
    private CommonEvaluateCountService commonEvaluateCountService;
    @Reference
    private MarketingShareService marketingShareService;
    @Reference
    private MarketingGiftService marketingGiftService;
    @Reference
    private MarketingCouponService marketingCouponService;
    @Reference
    private MarketingInviteLogService marketingInviteLogService;
    @Reference
    private FinanceOrderService financeOrderService;
    @Reference
    private FinanceInviteRewardService financeInviteRewardService;
    @Reference
    private OrderFareService orderFareService;


    /**
     * 获取开始位置
     **/
    public final static Integer ORDER_AVERAGE_SCORE_START = 0;
    /**
     * 获取长度
     **/
    public final static Integer ORDER_AVERAGE_SCORE_LENGTH = 100;


    @ApiOperation(value = "司机用户信息详情接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/info"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<DriverVo> driUserInfo(HttpServletRequest request) {
        return driverService.selInfo(getUserUid(request));
    }

    @ApiOperation(value = "司机个人信息设置接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/setInfo"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<Boolean> setDriUserInfo(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "face", value = "头像") @RequestParam(value = "face", required = false) String face,
            @ApiParam(name = "sex", value = "性别 1：男，2女") @RequestParam(value = "sex", required = false) Integer sex,
            @ApiParam(name = "name", value = "称呼") @RequestParam(value = "name", required = false) String name,
            HttpServletRequest request) {
        DriverDto driverDto = new DriverDto();
        driverDto.setUuid(getUserUid(request));
        driverDto.setUpdateOn(new Date());
        driverDto.setName(name);
        driverDto.setFace(face);
        driverDto.setSex(sex);
        return driverService.edit(driverDto);
    }

    @ApiOperation(value = "司机上传头像接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/uploadImage"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<String> uploadImage(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "avatar", value = "头像", required = true) @RequestParam(value = "avatar") MultipartFile avatar) {

        if (StringUtils.isNull(avatar)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "头像不能为空！");
        }
        //上传用户头像
        return FileUploadUtil.uploadImage(avatar, appid, "", Constants.UPLOAD_FOLDER_MYPIC);
    }


    @ApiOperation(value = "司机修改登录密码接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/user/reset"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<Boolean> reset(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "mobile", value = "手机号码", required = true) @RequestParam String mobile,
            @ApiParam(name = "identifyCode", value = "验证码", required = true) @RequestParam String identifyCode,
            @ApiParam(name = "idcard", value = "身份证", required = true) @RequestParam String idcard,
            @ApiParam(name = "password", value = "密码", required = true) @RequestParam String password,
            HttpServletRequest request) {

        //解析手机号码
        String decryptMobile = RandomUtil.randomDecrypt(mobile);
        //解析验证码
        String decryptIdentifyCode = RandomUtil.randomDecrypt(identifyCode);
        //解析身份证
        String decryptIdCard = RandomUtil.randomDecrypt(idcard);

        if (!ValidateUtils.validateMobile(decryptMobile)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "电话号码格式错误");
        }
        if (decryptIdentifyCode.length() != MagicConstant.INT_FOUR) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "验证码格式错误");
        }
        if (!ValidateUtils.checkIdCard(decryptIdCard)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "身份证号格式错误");
        }

        //解析密码
        String decryptPassword = RandomUtil.randomDecrypt(password);

        //获取用户
        Map<String, Object> map = MapUtils.build(3);
        map.put("mobile", decryptMobile);
        map.put("idCard", decryptIdCard);
        map.put("appid", appid);
        ResponseData<List<DriverDto>> responseData = driverService.getValidDriver(map);
        if (!responseData.isSuccess()) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "查无符合司机");
        }
        DriverDto driver = responseData.getData().get(0);
        if(driver.getResetPasswordTime()!=null){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if(sdf.format(driver.getResetPasswordTime()).equals(sdf.format(new Date()))){
                return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "今日已重置过密码，一天仅允许操作一次！");
            }
        }

        //142开头测试用户直接修改密码并return
        if (MagicConstant.STRING_ONE_FOUR_TWO.equals(decryptMobile.substring(0, MagicConstant.INT_THREE))) {
            return driverService.resetPsw(decryptPassword, driver.getUuid());
        }

        //验证验证码
        map.clear();
        map.put("mobile", decryptMobile);
        map.put("identifyCode", decryptIdentifyCode);
        map.put("appid", appid);
        map.put("status", CommonConstant.IDENTIFY_CODE_STATUS_UNUSED);
        CommonIdentifyDto identify = commonSmsService.get(map).getData();
        if (identify != null) {
            identify.setStatus(CommonConstant.IDENTIFY_CODE_STATUS_USED);
            commonSmsService.edit(identify);
        }
        return driverService.resetPsw(decryptPassword, driver.getUuid());
    }

    @ApiOperation(value = "司机验证验证码接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/user/verifyCode"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData verifyCode(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "mobile", value = "手机号码", required = true) @RequestParam String mobile,
            @ApiParam(name = "identifyCode", value = "验证码", required = true) @RequestParam String identifyCode,
            HttpServletRequest request) {

        String decryptMobile = RandomUtil.randomDecrypt(mobile);
        String mobileTop3 = decryptMobile.substring(0, 3);
        String decryptIdentifyCode = RandomUtil.randomDecrypt(identifyCode);
        if (!ValidateUtils.validateMobile(decryptMobile)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "电话号码格式错误");
        }

        if (!MagicConstant.STRING_ONE_FOUR_TWO.equals(mobileTop3)) {
            Map<String, Object> map = MapUtils.build(3);
            map.put("mobile", decryptMobile);
            map.put("identifyCode", decryptIdentifyCode);
            map.put("appid", appid);
            map.put("status", CommonConstant.IDENTIFY_CODE_STATUS_UNUSED);
            CommonIdentifyDto commonIdentifyDto = commonSmsService.get(map).getData();
            if (commonIdentifyDto == null) {
                return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "验证码错误");
            } else {
                //更新验证码
                commonIdentifyDto.setStatus(CommonConstant.IDENTIFY_CODE_STATUS_USED);
                commonSmsService.edit(commonIdentifyDto);
                return ResponseData.buildSuccessResponse("验证通过", null);
            }
        }
        return ResponseData.buildSuccessResponse("验证成功", null);
    }

    @ApiOperation(value = "司机证验手机&身份证接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/user/validate"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData validate(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "mobile", value = "手机号码", required = true) @RequestParam String mobile,
            @ApiParam(name = "idcard", value = "身份证", required = true) @RequestParam String idcard,
            @ApiParam(name = "type", value = "司机类型 1：出租车，2专车，3拼车") @RequestParam(value = "type", required = false) Integer type) {
        String decryptMobile = RandomUtil.randomDecrypt(mobile);
        String decryptIdCard = RandomUtil.randomDecrypt(idcard);
        if (!ValidateUtils.validateMobile(decryptMobile)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "手机号格式错误");
        }
        return driverService.validate(decryptMobile, decryptIdCard, appid, type);
    }

    @ApiOperation(value = "司机重新设置登录密码接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/resetByPsw"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<Boolean> resetByPsw(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "newPsw", value = "新密码", required = true) @RequestParam String newPsw,
            @ApiParam(name = "oldPsw", value = "旧密码", required = true) @RequestParam String oldPsw,
            HttpServletRequest request) {
        String decryptOldPwd = RandomUtil.randomDecrypt(oldPsw);
        String decryptNewPwd = RandomUtil.randomDecrypt(newPsw);
        return driverService.resetByPsw(getUserUid(request), decryptOldPwd, decryptNewPwd);
    }

    @ApiOperation(value = "司机获取前一天评价接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/evaluate"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<List<OrderEvaluateDto>> getListOfEvaluate(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "nowPage", value = "页码", required = true) @RequestParam Integer nowPage,
            HttpServletRequest request) {
        List<OrderEvaluateDto> oes = orderEvaluateService.getListOfEvaluate(getUserUid(request), new ApiPageParam(nowPage)).getData();
        if (oes == null) {
            return ResponseData.buildSuccessResponse("该司机尚无评价信息", Collections.emptyList());
        }
        return ResponseData.buildSuccessResponse("获取成功", oes);
    }


    @ApiOperation(value = "司机获取考核统计接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/examination"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<DriverSignLogVo> findExaminationList(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "startTime", value = "开始时间", required = true) @RequestParam String startTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true) @RequestParam String endTime,
            HttpServletRequest request) {
        startTime += " 00:00:00";
        endTime += " 23:59:59:";
        return orderFareService.findExaminationList(getUserUid(request), startTime, endTime);
    }


    @RequestMapping(value = {"/token/feedback/add"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "司机添加反馈接口", response = ResponseData.class)
    public ResponseData<Boolean> addFeedback(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "title", value = "反馈标题", required = false) @RequestParam(required = false) String title,
            @ApiParam(name = "content", value = "反馈内容", required = true) @RequestParam String content,
            HttpServletRequest request) {
        CommonFeedbackDto feedbackDto = new CommonFeedbackDto();
        feedbackDto.setUuid(StringUtils.buildUUID());
        feedbackDto.setAppid(appid);
        feedbackDto.setContent(content);
        feedbackDto.setTitle(content);
        feedbackDto.setIdentity(CommonConstant.DRIVER);
        feedbackDto.setUserUuid(getUserUid(request));
        feedbackDto.setCreateOn(new Date());
        feedbackDto.setStatus(CommonFeedbackDto.STATUS_UNREPLY);
        return commonFeedbackService.add(feedbackDto);
    }


    @RequestMapping(value = {"/token/feedback/list"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "司机获取反馈列表接口", response = ResponseData.class, notes = "list")
    public ResponseData<PageList<CommonFeedbackDto>> findFeedbackList(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "nowPage", value = "页码", required = true) @RequestParam Integer nowPage,
            HttpServletRequest request) {
        Map<String, Object> map = MapUtils.build(3);
        map.put("userUuid", getUserUid(request));
        map.put("identity", CommonConstant.DRIVER);
        return commonFeedbackService.queryPage(map, new ApiPageParam(nowPage));
    }

    @RequestMapping(value = {"/token/user/findEvaluateData"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "司机获取乘客评价统计数据接口", httpMethod = "POST", response = ResponseData.class, notes = "list")
    public ResponseData<DriverEvaluationVo> findEvaluateData(HttpServletRequest request) {
        DriverEvaluationVo evaluationVo = new DriverEvaluationVo();
        //获取司机累计信息 — 累计得分和累计订单数
        DriverDto driverDto = driverService.get(getUserUid(request)).getData();
        if (driverDto != null) {
            evaluationVo.setScore(driverDto.getScore());
            evaluationVo.setOrderCount(driverDto.getOrderCount());
        }
        //获取前一百单订单平均积分
        evaluationVo.setScoreOfRecent(orderEvaluateService.findAverageScoreByLength(getUserUid(request), ORDER_AVERAGE_SCORE_START,
                ORDER_AVERAGE_SCORE_LENGTH).getData());

        //获取司机星级订单统计
        CommonStarCountDto star = commonStarCountService.get(MapUtils.build("driverUuid", getUserUid(request))).getData();
        if (star != null) {
            evaluationVo.setCommonStarCountDto(star);
        }

        //获取司机评价标签统计
        List<CommonEvaluateCountDto> commonEvaluateCountDtos = commonEvaluateCountService.findListByDriverUuid(getUserUid(request)).getData();
        if (commonEvaluateCountDtos != null) {
            evaluationVo.setEvaluates(commonEvaluateCountDtos);
        }
        return ResponseData.buildSuccessResponse("获取成功", evaluationVo);
    }

    @ResponseBody
    @ApiOperation(value = "司机提现接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/cash"}, method = {RequestMethod.POST, RequestMethod.GET})
    public ResponseData<Boolean> cash(
            @ApiParam(name = "cash", value = "提现金额", required = true) @RequestParam String cash,
            @ApiParam(name = "collectAccount", value = "收款账号", required = true) @RequestParam String collectAccount,
            @ApiParam(name = "collectType", value = "收款类型 1：银联卡，2：微信 3.支付宝") @RequestParam Integer collectType,
            @ApiParam(name = "password", value = "登录密码", required = true) @RequestParam String password,
            @ApiParam(name = "poundage", value = "提现手续费") @RequestParam(required = false) String poundage,
            HttpServletRequest request) {
        cash = RandomUtil.randomDecrypt(cash);
        collectAccount = RandomUtil.randomDecrypt(collectAccount);
        if (ParamUtil.isIllegal(cash, collectAccount)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "金额不能为空");
        }
        //获取提现信息 计算手续费 判断可提现时间
        DriverVo driverVo = driverService.selInfo(getUserUid(request)).getData();
        if (driverVo == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "获取不到司机信息");
        }
        DriverDto driverDto = new DriverDto();
        driverDto.setUuid(driverVo.getUuid());
        driverDto.setBankAccountName(driverVo.getName());
        driverDto.setBankAccount(collectAccount);
        driverDto.setUpdateOn(new Date());
        CompletableFuture.runAsync(() -> driverService.edit(driverDto));
        //判断提现时间
        if (driverVo.getPoundageTitle() == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "提现失败，未配置提现规则");
        }
        if (driverVo.getCanWishdraw() != 1) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "提现失败，" + driverVo.getPoundageTitle());
        }

        //验证登陆密码是否与当前登陆的账户匹配
        ResponseData<Boolean> responseData = driverService.verifyIdentidy(getUserUid(request), RandomUtil.randomDecrypt(password));
        if (!responseData.isSuccess() || Boolean.FALSE.equals(responseData.getData())) {
            return responseData;
        }
        Double withdrawalCash = Double.parseDouble(cash);
        //获取手续费
        Double cashPoundage = 0d;
        //如果提现到银行卡 需计算手续费
        if (collectType == 1 && poundage != null) {
            cashPoundage = Double.valueOf(RandomUtil.randomDecrypt(poundage));
        }
        return driverCashService.addCash(getUserUid(request), collectType, collectAccount, withdrawalCash, cashPoundage);
    }

    @ApiOperation(value = "司机获取提现详情接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/cashInfo"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<DriverCashDto> cashInfo(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "cashUuid", value = "提现记录Uuid", required = true) @RequestParam String cashUuid,
            HttpServletRequest request) {
        if (StringUtils.isEmpty(cashUuid)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "参数不能为空");
        }
        Map<String, Object> map = MapUtils.build();
        map.put("uuid", cashUuid);
        map.put("userUuid", getUserUid(request));
        return driverCashService.get(map);
    }


    @ApiOperation(value = "司机设置听单模式接口", notes = "返回成功或失败消息", response = ResponseData.class)
    @RequestMapping(value = {"/token/user/remind"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<Boolean> remind(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "remindType", value = "听单模式 1：全部，2：实时 3：预约", required = true) @RequestParam Integer remindType,
            @ApiParam(name = "listenDown", value = "向下听单 0：不允许，1：允许", required = false) @RequestParam(required = false) Integer listenDown,
            @ApiParam(name = "appointTimeStart", value = "预约时间段（开始）") @RequestParam(required = false) String appointTimeStart,
            @ApiParam(name = "appointTimeEnd", value = "预约时间段（结束）") @RequestParam(required = false) String appointTimeEnd,
            @ApiParam(name = "sameWayModel", value = "顺路模式0 关闭 1开启") @RequestParam(required = false) Integer sameWayModel,
            @ApiParam(name = "rejectStationOrder", value = "不接火车站订单 0关闭 1开启") @RequestParam(required = false) Integer rejectStationOrder,
            @ApiParam(name = "sameWayAddress", value = "顺路地址") @RequestParam(required = false) String sameWayAddress,
            @ApiParam(name = "sameWayLng", value = "顺路经度") @RequestParam(required = false) Double sameWayLng,
            @ApiParam(name = "sameWayLat", value = "顺路纬度") @RequestParam(required = false) Double sameWayLat,
            HttpServletRequest request) {
        DriverRemindParam param = new DriverRemindParam();
        param.setRemindType(remindType);
        param.setListenDown(listenDown);
        param.setAppointTimeStart(ParamUtil.defaultIfNull(appointTimeStart,""));
        param.setAppointTimeEnd(ParamUtil.defaultIfNull(appointTimeEnd,""));
        param.setSameWayModel(sameWayModel);
        param.setRejectStationOrder(rejectStationOrder);
        param.setSameWayAddress(sameWayAddress);
        param.setSameWayLng(sameWayLng);
        param.setSameWayLat(sameWayLat);
        param.setUuid(getUserUid(request));

        return driverService.updRemind(param);
    }

    @RequestMapping(value = {"/token/accDetail/list"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "司机获取账单列表接口", notes = "")
    public ResponseData<Map<String, Object>> list(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "nowPage", value = "当前页") @RequestParam(required = false) Integer nowPage,
            @ApiParam(name = "dateType", value = "时间类型（0：月份，1：周数(结束时间为必填)）", required = true) @RequestParam int dateType,
            @ApiParam(name = "start", value = "开始时间（格式：月份：yyyy-MM，周数为：yyyy-MM-dd）", required = true) @RequestParam String start,
            @ApiParam(name = "end", value = "结束时间（格式：周数为：yyyy-MM-dd）") @RequestParam(required = false) String end,
            @ApiParam(name = "type", value = "类型（0：全部，1：收入，2：支出）", required = true) @RequestParam String type,
            HttpServletRequest request) {
        //判断时间格式及非空
        Map<String, Object> conditions = MapUtils.build(10);
        conditions.put("driverUuid", getUserUid(request));
        //0全部，1收入，2支出
        conditions.put("type", type);
        //格式：月份：2015-06，周数为：2016-01-01
        conditions.put("start", start);
        //格式：周数为：2016-01-01
        conditions.put("end", end);
        //0:月份 1：周数
        conditions.put("dateType", dateType);
        return financeOrderService.driverBill(conditions, new ApiPageParam(nowPage));
    }


    @RequestMapping(value = {"/token/accDetail/listCash"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "司机获取提现列表接口", notes = "返回的status 1.提现失败，2提现成功，3提现中")
    public ResponseData<PageList<DriverCashDto>> list(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "nowPage", value = "当前页") @RequestParam(required = false) Integer nowPage,
            HttpServletRequest request) {
        Map<String, Object> params = MapUtils.build();
        params.put("driverUuid", getUserUid(request));
        return driverCashService.queryPage(params, new ApiPageParam(nowPage));
    }


    @RequestMapping(value = {"/token/work/on"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "司机上班接口", notes = "上班")
    public ResponseData<Boolean> on(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "onWorkLng", value = "出车经度", required = false) @RequestParam(required = false) Double onWorkLng,
            @ApiParam(name = "onWorkLat", value = "出车纬度", required = false) @RequestParam(required = false) Double onWorkLat,
            @ApiParam(name = "uploadText", value = "长连接上传的报文", required = false) @RequestParam(required = false) String uploadText,
            HttpServletRequest request) {
        return this.driverService.onWork(getUserUid(request), onWorkLng, onWorkLat, uploadText);
    }

    @RequestMapping(value = {"/token/work/off"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "司机下班接口", notes = "下班")
    public ResponseData<Boolean> off(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "offWorkLng", value = "收车经度", required = false) @RequestParam(required = false) Double offWorkLng,
            @ApiParam(name = "offWorkLat", value = "收车纬度", required = false) @RequestParam(required = false) Double offWorkLat,
            @ApiParam(name = "uploadText", value = "长连接上传的报文", required = false) @RequestParam(required = false) String uploadText,
            HttpServletRequest request) {
        return this.driverService.offWork(getUserUid(request), offWorkLng, offWorkLat, uploadText);
    }


    @RequestMapping(value = {"/token/work/isWork"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "获取司机上班状态接口", notes = "上班")
    public ResponseData<Integer> isWork(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "type", value = "司机类型（1.出租车，2专车 3跨城拼车）", required = true) @RequestParam String type,
            HttpServletRequest request) {
        Map<String, Object> map = MapUtils.build();
        map.put("uuid", getUserUid(request));
        map.put("type", type);
        DriverDto driverDtoData = driverService.get(map).getData();
        if (driverDtoData == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "获取不到司机信息");
        }
        return ResponseData.buildSuccessResponse("获取状态成功", driverDtoData.getIsWork());
    }


    @ResponseBody
    @RequestMapping(value = {"/token/share/info"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "获取司机分享信息", notes = "获取司机分享信息", response = ResponseData.class)
    public ResponseData listActivity(
            @ApiParam(name = "token", value = "token", required = true) @RequestParam String token,
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid) {
        // 如果查询不到的话会被拦截器拦截 所以这里不需要判断是否查询的到
        Map<String, String> driverMap = getDriverByToken4Cache(driverService, token);
        if (driverMap == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "获取用户信息错误");
        }
        Map<String, Object> map = MapUtils.build();
        map.put("clientSide", 2);
        map.put("status", 1);
        MarketingShareVo marketingShareVo = marketingShareService.findVo(map).getData();
        //拼接url把邀请人的手机号和邀请人类型拼接到url中
        if (marketingShareVo != null) {
            //获取api接口地址 在拼接获取到的路径
            StringBuilder sBuilder = new StringBuilder(SYS_CONFIG.getApiHost());
            sBuilder.append(marketingShareVo.getLinkUrl());
            if (marketingShareVo.getLinkUrl().contains(MagicConstant.SYMBOL_QUESTION_MARK)) {
                sBuilder.append("&");
            } else {
                sBuilder.append("?");
            }
            sBuilder.append("appid=").append(appid).append("&inviter=").append(driverMap.get("mobile")).append("&inviterType=2");
            marketingShareVo.setLinkUrl(sBuilder.toString());
            //获取注册和司机邀请礼包优惠券总额
            map.clear();
            map.put("list", Lists.newArrayList(3));
            map.put("registerDefault", 1);
            BigDecimal inviteeMoney = marketingCouponService.getSumMoney(map).getData();
            if (inviteeMoney == null) {
                inviteeMoney = BigDecimal.ZERO;
            }
            // 获取司机邀请乘客返现金额
            BigDecimal awardAmount = marketingGiftService.getAwardAmount(1).getData();
            if (awardAmount == null) {
                awardAmount = BigDecimal.ZERO;
            }
            marketingShareVo.setInviteeMoney(inviteeMoney);
            marketingShareVo.setAwardAmount(awardAmount);
            map.clear();
            map.put("type", 3);
            map.put("status", 1);
            map.put("subType", 1);
            MarketingGiftDto marketingGiftDto = marketingGiftService.findGiftByMap(map).getData();
            if (marketingGiftDto != null) {
                marketingShareVo.setInvitedGiftName(marketingGiftDto.getInvitedGiftName());
                marketingShareVo.setInvitedRewardMethod(marketingGiftDto.getInvitedRewardMethod());
            }
            return ResponseData.buildSuccessResponse("获取成功", marketingShareVo);
        }
        return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "获取不到数据", null);
    }

    @RequestMapping(value = {"/token/invite/driver"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "获取司机邀请司机信息", notes = "获取司机邀请司机信息", response = ResponseData.class)
    public ResponseData<Map<String, Object>> inviteDriver(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "token", value = "token", required = true) @RequestParam String token) {
        Map<String, Object> dataInfo = new HashMap<>(16);
        Map<String, Object> activeInfo = new HashMap<>(16);
        Map<String, Object> inviteLog = new HashMap<>(16);
        // 如果查询不到的话会被拦截器拦截 所以这里不需要判断是否查询的到
        Map<String, String> driverMap = getDriverByToken4Cache(driverService, token);
        if (driverMap == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "获取用户信息错误");
        }
        Map<String, Object> map = MapUtils.build();
        map.put("clientSide", 3);
        map.put("status", 1);
        ResponseData<MarketingShareDto> responseData = marketingShareService.get(map);
        //拼接url把邀请人的手机号和邀请人类型拼接到url中
        if (responseData.isSuccess() && responseData.getData() != null) {
            MarketingShareDto marketingShareDto = responseData.getData();
            StringBuilder linkUrlSb = new StringBuilder(SYS_CONFIG.getApiHost());
            linkUrlSb.append(marketingShareDto.getLinkUrl());
            if (marketingShareDto.getLinkUrl().indexOf(MagicConstant.SYMBOL_QUESTION_MARK) != -1) {
                linkUrlSb.append("&");
            } else {
                linkUrlSb.append("?");
            }
            linkUrlSb.append("appid=").append(appid).append("&inviter=").append(driverMap.get("mobile")).append("&inviterType=2&type=").append(driverMap.get("type"));
            // 获取司机邀请司机返现金额
            BigDecimal awardAmount = marketingGiftService.getAwardAmount(2).getData();
            if (awardAmount == null) {
                awardAmount = new BigDecimal(0);
            }
            activeInfo.put("linkUrl", linkUrlSb.toString());
            activeInfo.put("awardAmount", awardAmount);
            activeInfo.put("linkTitle", marketingShareDto.getLinkTitle());
            activeInfo.put("linkContent", marketingShareDto.getLinkContent());
            activeInfo.put("linkImg", marketingShareDto.getLinkImg());
        } else {
            activeInfo.put("linkUrl", "");
            activeInfo.put("awardAmount", "0");
            activeInfo.put("linkTitle", "");
            activeInfo.put("linkContent", "");
            activeInfo.put("linkImg", "");
        }
        // 获取已经邀请并且审核通过的司机
        List<Map<String, Object>> inviteDriverList = marketingInviteLogService.listInviteDriver(driverMap.get("mobile")).getData();
        inviteLog.put("inviteDriverList", inviteDriverList);
        inviteLog.put("inviteCount", inviteDriverList.size());
        // 获取司机邀请司机得到的返现金额
        BigDecimal sumAwardAmount = financeInviteRewardService.getSumDriverAwardAmount(driverMap.get("uuid"),
                FinanceConstant.DRIVER_INVITE_PASSENGER_INVITE_REWARD).getData();
        inviteLog.put("sumAwardAmount", sumAwardAmount);
        dataInfo.put("activeInfo", activeInfo);
        dataInfo.put("inviteLog", inviteLog);
        return ResponseData.buildSuccessResponse(dataInfo);
    }

    @RequestMapping(value = {"/token/marketing/isOpenCity"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "判断司机位置是否开通乘客邀请好友城市", notes = "获取乘客邀请好友开通城市", response = ResponseData.class)
    public ResponseData<Map<String, Boolean>> isOpenCity(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "token", value = "token", required = false) @RequestParam(required = false) String token,
            @ApiParam(name = "adCode", value = "adCode", required = false) @RequestParam(required = false) String adCode) {
        if (adCode == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "未获取定位点");
        }
        return marketingGiftService.isOpenCity(adCode, CommonConstant.BUSINESS_TYPE_POOL);
    }
}
